var typeDetailVue = new Vue({
	el: "#app",
	data: {
		title: "",
		imgUrl: imgUrl,
		saleFlag: true,
		priceFlag: false,
		topFlag: false,
		first: true,
		typeId: null,
		pageNum: 1,
		isBottom: false,
		isExcute: true,
		products: [],
		isNoData: false 
	},
	methods: {
		saleFlagBtn: function() {
			if (this.saleFlag) return;
			this.saleFlag = !this.saleFlag;
			this.priceFlag = false;
			this.first = true;
			this.topFlag = false;
			this.products = [];
			this.getData();
		},
		priceFlagBtn: function() {
			if (this.priceFlag) {
				this.first = false;
				this.topFlag = !this.topFlag;
				this.products = [];
				this.getData();
				return;
			};
			if (this.first) {
				this.first = false;
				this.topFlag = !this.topFlag;
			}
			this.priceFlag = !this.priceFlag;
			this.saleFlag = false;
			this.products = [];
			this.getData();
		},
		getData: function() {
			var s = this;
			if (this.isbottom) return !1;
			wx.showLoading({
				title: "加载中",
				mask: !0
			});
			var a = {
				currentPage: s.pageNum,
				pageSize: 10,
				typeId: s.typeId,
				salesSort: s.saleFlag ? 1 : 0,
				priceSort: s.priceFlag ? s.topFlag ? 1 : 2 : 0
			};
			this.$http.post(baseUrl + "wap/product/index", a).then(function(t) {
				wx.hideLoading();
				var a = t.data;
				if (!a.success) {
					wx.showToast({
						title: a.description,
						icon: "none",
						duration: 2e3,
						mask: !0
					})
				} else {
					if (0 == a.data.length && s.pageNum > 1) {
						s.isBottom = true;
						wx.showToast({
							title: "已经到最底下了",
							icon: "none",
							duration: 1e3,
							mask: !0
						});
					} else if (a.data.length > 0 && 1 == s.pageNum) {
						a.data.forEach(function(e) {
							e.homePath = e.logoPath.split(",")[0];
							s.products.push(e);
						});
						s.isNoData = false;
					} else if (0 == a.data.length && 1 == s.pageNum) {
						s.showFlag = false;
						s.isNoData = true; 
					} else {
						a.data.forEach(function(e) {
							e.homePath = e.logoPath.split(",")[0];
							s.products.push(e);
						});
					}
				}
				this.isExcute = false;
			}).catch(function(t) {
				this.isExcute = false;
				console.log(t), wx.hideLoading(), wx.showToast({
					title: "网络错误，请检查网络",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		handleScroll: function() {
			// 防止重复
			if (this.isExcute) {
				return;
			}
			if (this.isBottom) {
				return;
			}
			var flag = srollEvent.isReachBottom();
			if (!flag) {
				return;
			}
			this.isExcute = true;
			this.pageNum++;
			this.getData();
		},
		toDetail: function(item) {
			Jump.to(page.product.detail,"guid="+item.productGuid);
		}
	},
	mounted: function() {
		window.addEventListener("scroll", this.handleScroll, {
			passive: false
		});
	},
	created: function() {
		var typeId = URLParam.get("typeId");
		var title = URLParam.get("title");
		this.title = title;
		this.typeId = typeId;
		this.getData();
	},
	destroyed() { //离开该页面需要移除这个监听的事件
		window.removeEventListener('scroll', this.handleScroll)
	}
});
